package com.example.a2205douyin;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;

import com.blankj.utilcode.util.ToastUtils;
import com.example.a2205douyin.adapter.MyFragAdapter;
import com.example.a2205douyin.baseMVVM.view.BaseViewActivity;
import com.example.a2205douyin.databinding.ActivityDouyinBinding;
import com.example.a2205douyin.fragment.FriFragment;
import com.example.a2205douyin.fragment.HomeFragment;
import com.example.a2205douyin.fragment.MessFragment;
import com.example.a2205douyin.fragment.MineFragment;
import com.google.android.material.badge.BadgeDrawable;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import java.util.ArrayList;
import java.util.List;

public class DouyinActivity extends BaseViewActivity<ActivityDouyinBinding> {
    List<Fragment> list= new ArrayList<>();
    MyFragAdapter myFragAdapter;

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {

        requestPermissions(new String[]{
                "android.permission.VIBRATE",
                "android.permission.RECORD_AUDIO" ,
                "android.permission.CAMERA",
                "android.permission.ACCESS_NETWORK_STATE",
                "android.permission.WRITE_EXTERNAL_STORAGE" ,
                "android.permission.ACCESS_FINE_LOCATION",
                "android.permission.GET_TASKS" ,
                "android.permission.ACCESS_WIFI_STATE" ,
                "android.permission.CHANGE_WIFI_STATE" ,
                "android.permission.WAKE_LOCK",
                "android.permission.MODIFY_AUDIO_SETTINGS",
                "android.permission.READ_PHONE_STATE",
                "android.permission.RECEIVE_BOOT_COMPLETED",
                "android.permission.FOREGROUND_SERVICE",
                "android.permission.ACCESS_COARSE_LOCATION"
        },100);



        list.add(new HomeFragment());
        list.add(new FriFragment());
        list.add(new MessFragment());
        list.add(new MineFragment());
        myFragAdapter = new MyFragAdapter(this,list);
        binding.vp.setAdapter(myFragAdapter);

        //上下联动
        binding.vp.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                switch (position){
                    case 0:
                        binding.bottom.getMenu().getItem(0).setChecked(true);
                        break;
                    case 1:
                        binding.bottom.getMenu().getItem(1).setChecked(true);
                        break;
                    case 2:
                        binding.bottom.getMenu().getItem(3).setChecked(true);
                        break;
                    case 3:
                        binding.bottom.getMenu().getItem(4).setChecked(true);
                }
            }
        });
        BadgeDrawable badge = binding.bottom.getOrCreateBadge(R.id.friends);//显示未读消息原点
        BadgeDrawable badge1 = binding.bottom.getOrCreateBadge(R.id.message);
        badge1.setNumber(100);//设置未读消息数量
        //点击菜单，上方联动
        binding.bottom.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()){
                    case R.id.home:
                        binding.vp.setCurrentItem(0);
                        break;
                    case R.id.friends:
                        binding.vp.setCurrentItem(1);
                        badge.setVisible(false);
                        break;
                    case R.id.fabu:
                        startActivity(new Intent(DouyinActivity.this,ZhiboActivity.class));
                        break;
                    case R.id.message:
                        binding.vp.setCurrentItem(2);
                        badge1.setVisible(false);
                        break;
                    case R.id.mine:
                        binding.vp.setCurrentItem(3);
                        break;
                }
                return false;
            }
        });
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_douyin;
    }
}